package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.wemedia.WmUserControllerApi;
import com.heima.model.common.constants.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {

    @Autowired
    private WmUserService wmUserService;
    /**
     * 保存自媒体用户 feign调用
     *
     * @param wmUser
     * @return wmUser 需要主键返回
     */
    @Override
    @PostMapping("/save")
    public WmUser save(@RequestBody WmUser wmUser) {
        if (wmUserService.save(wmUser)) {
            return wmUser;
        } else {
            return null;
        }
    }

    /**
     * 根据登录名查询当前用户 feign调用
     *
     * @param name
     * @return
     */
    @Override
    @GetMapping("/findByName/{name}")
    public WmUser findByName(@PathVariable("name") String name) {
        return wmUserService.getOne(
                Wrappers.<WmUser>lambdaQuery()
                .eq(WmUser::getName,name)
        );
    }

    /**
     * 根据id查询自媒体用户 feign调用
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/findById/{id}")
    public WmUser findWmUserById(@PathVariable("id") Integer id) {
        return wmUserService.getById(id);
    }
}
